'''
Created on Nov 5, 2011

@author: alebalbin
'''
def read_file(file,fcol):
    ifile=open(file)
    gl=set()
    for l in ifile:
        f=l.strip('\r\n').split('\t')
        gl.add(f[fcol])
    ifile.close()
    return gl

def compare_list(file1,file2):
    f1col,f2col=0,1
    of=open(file1.replace('.txt','_isec_MouseRASinteractome.txt'),'w')
    l1=read_file(file1,f1col)
    l2=read_file(file2,f2col)
    isecl=l1.intersection(l2)
    print "intersection list= %d, original l1= %d, l2= %d, percent=%f"%(len(isecl),len(l1),len(l2), float(len(isecl))/len(l2) ) 
    of.write(",".join(isecl).replace(',','\t'))
    
ofile='/Users/alebalbin/Documents/projects/nsclc_kras_dep/Data/IP_MS/IP-MS_SAINT_000_result_nov1-Plus-FlowT.txt'
file2='/Users/alebalbin/Documents/projects/nsclc_kras_dep/Data/IP_MS/Mouse_RAS_Interactome_Nov1.txt'

compare_list(ofile,file2)